<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<title>无标题文档</title>
	<link href="/static/css/default.css" rel="stylesheet" type="text/css">
	<link href="/static/css/style/green.css" rel="stylesheet" type="text/css" id='link'>
	<link rel="stylesheet" href="/static/FileUpload/css/jquery.fileupload.css" />
</head>

<body style="overflow:hidden; padding:10px;">
	<form>
		<div id="app">
			<table class="formtable" style="width:580px;">

				<tbody>
					<tr>
						<td>卡号</td>
						<td>备注</td>
						<td>时间</td>
						<td>操作</td>
					</tr>
					<tr v-for="uitem in arrayData">
						<td>{{uitem.cardnumber}}</td>
						<td>{{uitem.desc}}</td>
						<td>{{uitem.createtime}}</td>
						<td>
							<a v-on:click="choosenumber(uitem)">设置为学号</a>
								<a v-on:click="vdel(uitem)">删除</a>
						</td>
					</tr>

				</tbody>
			</table>
			<table class="formtable" style="width:580px;">

				<tbody>

					<tr>
						<td class="tlabel">卡号</td>
						<td>
							<input type="text" class="forminput inputstyle1" id="cardnumber" value="">
						</td>
					</tr>

					<tr>
						<td class="tlabel">备注</td>
						<td>
							<input type="text" class="forminput inputstyle1" id="desc" value="">
						</td>
					</tr>



				</tbody>

			</table>

			<div class="formbtn">
				<input type="button" value="保存" class="btnsave">
				<input type="button" value="取消" class="btncancel">
			</div>
			<input type="hidden" id="studentid" value="{$id}" />
			
		</div>
	</form>


</body>
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/common.js"></script>
<script type="text/javascript" src="/static/js/vue2.js"></script>
<script src="/static/js/layer/layer.js"></script>
<script src="/static/FileUpload/js/vendor/jquery.ui.widget.js"></script>
<script src="/static/FileUpload/js/jquery.iframe-transport.js"></script>
<script src="/static/FileUpload/js/jquery.fileupload.js"></script>
<script>
	
	var app = new Vue({
		el: '#app',
		data: {
		
			arrayData: []
		},
		methods: {
			getdata: function () {
				var _self = this;//保存this的指向
				var studentid =$("#studentid").val();
				$.post('/Index/Student/getcard', {studentid:studentid},function (data) {
					_self.arrayData = data.list;
				});
			},
			choosenumber:function(uitem){
				var self = this;
				parent.layer.confirm('确定要设置为学号吗?', {
					btn: ['是', '否'] //按钮
				}, function () {
					parent.layer.closeAll('dialog');
					$.post("/Index/Student/setnumber", { "studentid": uitem.studentid,"cardnumber":uitem.cardnumber }, function (data) {
						if (data.status == 200) {
							layer.msg(data.message);
							parent.reloadiframe();
						} else {
							layer.msg(data.message);
						}
					});
				}, function () {

				});


			},
			vdel:function(uitem){
				var self = this;
				parent.layer.confirm('确定要删除吗?', {
					btn: ['是', '否'] //按钮
				}, function () {
					parent.layer.closeAll('dialog');
					$.post("/Index/Student/carddel", { "id": uitem.id }, function (data) {
						if (data.status == 200) {
							layer.msg(data.message);
							self.getdata("");
						} else {
							layer.msg(data.message);
						}
					});
				}, function () {

				});
			}

		},
		created: function () {  //初始化事件里边去调用查询方法
			this.getdata();
		}
	});

	$(function () {

		$(".btnsave").click(function () {
			var id = "";
			var cardnumber = $("#cardnumber").val();
			var desc = $("#desc").val();
			var studentid = $("#studentid").val();
			
			if(cardnumber==""){
				layer.msg("请输入卡号");
				return;
			}


			$.post("/Index/Student/addcard", {
				"id": id, "cardnumber": cardnumber, "desc": desc, "studentid": studentid
			}, function (data) {
				if (data.status == 200) {
					layer.msg(data.message);
					$("#cardnumber").val("");
					$("#desc").val("");
					app.getdata();
					window.parent.reloadiframe();
				} else {
					layer.msg(data.message);
				}
			});
		});
		$(".btncancel").click(function () {
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		});
	});


</script>

</html>